<?php

namespace App\Admin\Renderable;

use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use App\Models\User;

class UserTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $id = $this->id;

        return Grid::make(new User(), function (Grid $grid) {
            $grid->column('id');
            $grid->column('name');
            $grid->column('phone');
            $grid->column('avatar','头像')->image('',30,30);
            $grid->column('sex','性别')->display(function($sex){
                return $sex==1 ? '男' : '女';
            });
            $grid->column('birthday','生日');

            // 指定行选择器选中时显示的值的字段名称
            // 如果表格数据中带有 “name”、“title”或“phone”字段，则可以不用设置
            $grid->rowSelector()->titleColumn('name');

            $grid->quickSearch(['id', 'phone', 'name']);

            $grid->paginate(10);
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('phone')->width(4);
                $filter->like('name')->width(4);
            });
        });
    }
}